import { CommandSubClass } from "../class/Command";
import { CommandNotFindError } from "../class/errors";
import { CallMethod } from "../commands/CallMethod";
import { CheckRole } from "../commands/CheckRole";
import { GameStatus } from "../commands/GameStatus";
import { LookAllPlayer } from "../commands/LookAllPlayer";
import { LookCards } from "../commands/LookCards";
import { LookCommands } from "../commands/LookCommands";
import { LookMethod } from "../commands/LookMethod";
import { LookMethods } from "../commands/LookMethods";
import { LookRoles } from "../commands/LookRoles";
import { OutCard } from "../commands/OutCard";
import { Status } from "../commands/Status";
import { TakeCard } from "../commands/TakeCard";

export class CommandFactory {
    static commands: typeof CommandSubClass[] = [CheckRole, TakeCard, Status, OutCard, CallMethod, LookMethod, LookMethods, LookRoles, LookCommands, LookCards, GameStatus, LookAllPlayer]
    static add(commandSubClass: typeof CommandSubClass) {
        this.commands.push(commandSubClass)
    }
    static getByName(name: string) {
        const command = this.commands.find(e => e.test(name));
        if (command === undefined) {
            throw new CommandNotFindError();
        } else {
            return command;
        }
    }
    static getAllCommandNames() {
        return this.commands.map(ComamndClass => ComamndClass.commandName);
    }
}